package com.example.a17376052_wcp_finaltest.fragment;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.a17376052_wcp_finaltest.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import adapter.FruitAdapter;
import adapter.GalleryAdapter;
import entire.Fruit;

public class Fragment_1 extends Fragment {
    private RecyclerView mRecyclerView;
    private GalleryAdapter mAdapter;
    private List<Integer> mDatas;
    private ListView fruitListView;
    private List<Fruit> fruitList = new ArrayList<Fruit>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view = inflater.inflate(R.layout.fragment_1, container,false);
        initDatas();
        //得到控件
        mRecyclerView =view.findViewById(R.id.id_recyclerview_horizontal);
        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        //设置适配器
        mAdapter = new GalleryAdapter(getContext(), mDatas);
        mRecyclerView.setAdapter(mAdapter);


        fruitListView = (ListView) view.findViewById(R.id.fruitListView1);

        fruitList.add(new Fruit("艾菲勒法式马卡龙甜点24枚西式糕点点心小蛋糕零食", R.mipmap.vbbb));
        fruitList.add(new Fruit("巧师傅八拼网红千层水果蛋糕",R.mipmap.vcccc));
        fruitList.add(new Fruit("PHbalance网红慕斯小蛋糕半熟芝士蛋糕海盐千层抹茶",R.mipmap.viiii));
        fruitList.add(new Fruit("俄罗斯进口双山提拉米苏千层蛋糕500g", R.mipmap.vmmmm));
        fruitList.add(new Fruit("幸福西饼蛋糕下午茶生日聚会网红甜品", R.mipmap.vnnn));
        fruitList.add(new Fruit("新好利来青梅芝士休闲小零食点心甜品小蛋糕", R.mipmap.vtttt));
        fruitList.add(new Fruit("ebeecake小蜂蜜北海道双层芝士蛋糕半熟芝士", R.mipmap.vzzzz));
        fruitList.add(new Fruit("轻半熟芝士蛋糕早餐零食手工糕点", R.mipmap.vooooo));


        FruitAdapter adapter = new FruitAdapter(getActivity(), R.layout.fruit_item,fruitList);
        fruitListView.setAdapter(adapter);

        fruitListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getActivity(),"谢谢你这么好看还要关注我"+position,Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(getActivity(),Main2Activity.class);
                startActivity(intent);



            }
        });

        return view;

    }


    private void initDatas()
    {
        mDatas = new ArrayList<Integer>(Arrays.asList(R.drawable.aaa,
                R.drawable.ttt, R.drawable.qir, R.drawable.qit, R.drawable.qiu,
                R.drawable.qiy));
    }
}


